package com.bestcem.xm.openplatform.mq.send.biz.impl;

import cn.hutool.json.JSONUtil;
import com.bestcem.xm.common.core.config.mq.XmMessageProducer;
import com.bestcem.xm.common.core.constant.StreamMqBinderConstants;
import com.bestcem.xm.openplatform.mq.dto.OpenplatformExtParamUpdateDto;
import com.bestcem.xm.openplatform.mq.send.biz.OpenplatformMessageSendService;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class OpenplatformMessageSendServiceImpl implements OpenplatformMessageSendService {

    private final XmMessageProducer messageProducer;

    public OpenplatformMessageSendServiceImpl(XmMessageProducer messageProducer) {
        this.messageProducer = messageProducer;
    }
    //private XmMessageProducer messageProducer;
    //
    //@Autowired
    //public void setMessageProducer(XmMessageProducer messageProducer) {
    //    this.messageProducer = messageProducer;
    //}


    @Override
    public void openplatformExtparamUpdateSend(OpenplatformExtParamUpdateDto dto) {
        try {
            messageProducer.send(StreamMqBinderConstants.OPENPLATFORM_EXTPARAM_UPDATE, dto);
        } catch (JsonProcessingException e) {
            log.error("[openplatform]同步投放外部参数表中的，外部参数描述发送消息失败:{}", JSONUtil.toJsonStr(dto), e);
        }
    }

    @Override
    public void openplatformDeliverSurveyExtVersionUpdateSend(OpenplatformExtParamUpdateDto dto) {
        try {
            messageProducer.send(StreamMqBinderConstants.OPENPLATFORM_DELIVER_SURVEY_EXT_VERSION_UPDATE, dto);
        } catch (JsonProcessingException e) {
            log.error("[openplatform]同步投放外部参数表中的，投放version发送消息失败:{}", JSONUtil.toJsonStr(dto), e);
        }
    }
}
